package com.yuyu.common.util;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.BeanUtils;

/**
 * @author yuyu
 * @date 2018/12/27
 */
public class ListUtil {


    public static <T, C> List<C> copyPOJO(List<T> t, Class<C> c) {
        if (t == null || c == null) {
            return null;
        } else if (t.isEmpty()) {
            return new ArrayList<>();
        }
        List<C> result = new ArrayList<>();
        t.forEach(v -> {
            C target = null;
            try {
                target = c.newInstance();
            } catch (Exception e) {
                e.printStackTrace();

            }
            if (target != null){
                BeanUtils.copyProperties(v, target);
                result.add(target);
            }
        });

        return result;
    }
}
